package com.zmj.sy.mom.srv.aps.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.zmj.sy.mom.srv.aps.bean.entity.mes.WorkDetailTask;
import com.zmj.sy.mom.srv.aps.bean.entity.workQueue.MesWorkDetail;
import com.zmj.sy.mom.srv.aps.bean.vo.apsworkdetail.PdaWorkDetailResVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MesWorkDetailMapper extends SyMapper<MesWorkDetail> {
    @Select(" SELECT mwd.constructno as constructno,mwd.delay_count as delayCount ,mwd.plan_start_time as planStartTime ,mwd.plan_end_time as planEndTime , mwd.plmid as plmid ,mwd.shift_num as shiftNum,mwd.phase_code as phaseCode,mwd.part_name as partName,mwd.op_size_note as opSizeNote,mwd.mater_weight as materWeight,SUM(mwd.plan_count) as planTotalQty,sum(IFNULL(mwr.success_count,0) ) as comTotalQty from tb_mes_work_detail  mwd " +
            " left join ( SELECT tr.plmid,tr.phase_code ,tr.construct_no, sum(tr.success_count) as success_count from tb_mes_work_record  tr  where  tr.type = 2 AND tr.work_type = 2 AND tr.create_date_time >= #{startTime}  AND tr.create_date_time <  #{endTime} GROUP BY   plmid,phase_code ,construct_no) mwr " +
            " on mwd.plmid=mwr.plmid and mwd.phase_code=mwr.phase_code and mwd.constructno=mwr.construct_no " +
            "  ${ew.customSqlSegment} ")
    List<PdaWorkDetailResVo> pdaDateMesWorkDetail(@Param("startTime") String startTime,@Param("endTime") String endTime,@Param(Constants.WRAPPER) QueryWrapper<MesWorkDetail> qw);
}
